﻿using CarRental.DataAccessLayer;
using CarRental.Helpers;
using CarRental.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CarRental.Account
{
    public partial class Login : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register";
            //OpenAuthLogin.ReturnUrl = Request.QueryString["ReturnUrl"];

            //var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
            //if (!String.IsNullOrEmpty(returnUrl))
            //{
            //    RegisterHyperLink.NavigateUrl += "?ReturnUrl=" + returnUrl;
            //}
        }

        protected void btnLogin_Click(object sender, EventArgs e) {
            Wcf _wcf = new Wcf();
            List<user> _userLst = _wcf.GetUser().ToList<user>();

            string _loginName = tbUserName.Text;
            string _password = tbPassword.Text;

            _userLst = _userLst.Where(w => w.login_name.ToUpper() == _loginName.ToUpper() && w.password == _password).ToList();
            if (_userLst.Any()) {
                Shared.LoginInfo.Authorized = true;
                Response.Redirect("~/");
            }
        }

    }
}